﻿#ifndef PASSIVEEQUIPMENT_H
#define PASSIVEEQUIPMENT_H

#include "src/util/messageutil.h"
#include "src/util/conversionutil.h"
#include "src/util/parseutil.h"
#include "src/util/stringutil.h"
#include "src/util/uiutil.h"
#include "src/enum/secsenum.h"
#include "src/messagetext/text.h"

#include <QObject>
#include <QTcpSocket>
#include <QTcpServer>

/*
 * 需要注意:设备端发送Message的行为不会造成XXXState的改变
 * XXXState的更改必须要在读取解析到Host发送过来的信息之后再进行决定
 */

class PassiveEquipment : public QObject
{
    Q_OBJECT
public:
    PassiveEquipment();

    void BindPort(int port);

    /*
     * 让设备端从己方发出PrimaryMessage
     */
    void SendPrimaryMessage(quint16 sessionId,
                            quint32 transactionId,
                            quint8 stream,
                            quint8 function);
    /*
     * 让设备端从己方发出ControlMessage
     * 主要就是Select.Req, DeSelect.Req, LinkTest.Req
     * 三种类型消息
     */
    void SendControlMessage(QByteArray message);


    /*
     * 判断一个message是否为S1F13
     */
    bool Is_S1F13(QByteArray message);

    /*
     * 判断一个message是否为S1F13
     */
    bool Is_S1F14(QByteArray message);

    void DisConnect();
signals:
    void ConnectionStateChange(
        SecsEnum::ConnectionState currentConnectionState);

    void CommunicationStateChange(
        SecsEnum::CommunicationState currentCommunicationState);

    void ControlStateChange(
        SecsEnum::ControlState currentControlState);

    void SendMsg(QString message);

private:
    friend struct PassiveEquipmentPrivate;

    std::shared_ptr<PassiveEquipmentPrivate> d;
};

#endif // PASSIVEEQUIPMENT_H
